<?php
/**
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; version 3 of the License.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 */

/**
 * Shorthand to superglobals
 * @author Vincze Tamás pilou@pilou.hu
 */
class SG {

	/**
	 * Gets the value of the superglobal if its set, returns default if not set or it's empty
	 * @access protected
	 * @access static
	 * @param string $type
	 * @param string $name
	 * @param mixed $default
	 * @return mixed
	 */
	protected static function _getValue($type, $name, $default){
		$className = "\Core\HTTP\Superglobal\\".ucfirst($type);
		$value = $className::getInstance()->$name;
		return (is_null($value) || \Util\Validate::isEmpty($value)) ? $default : $value; 
	}
	
	/**
	 * Get post value
	 * @access public
	 * @access static
	 * @param string $name
	 * @param mixed $default
	 * @return mixed
	 */
	public static function post($name, $default = null){
		return self::_getValue("Post", $name, $default);
	}
	
	/**
	 * Get get value
	 * @access public
	 * @access static
	 * @param string $name
	 * @param mixed $default
	 * @return mixed
	 */
	public static function get($name, $default = null){
		return self::_getValue("Get", $name, $default);
	}

	/**
	 * Get server value
	 * @access public
	 * @access static
	 * @param string $name
	 * @param mixed $default
	 * @return mixed
	 */
	public static function server($name, $default = null){
		return self::_getValue("Server", $name, $default);
	}

	/**
	 * Get cookie value
	 * @access public
	 * @access static
	 * @param string $name
	 * @param mixed $default
	 * @return mixed
	 */
	public static function cookie($name, $default = null){
		return self::_getValue("Cookie", $name, $default);
	}

	/**
	 * Get session value
	 * @access public
	 * @access static
	 * @param string $name
	 * @param mixed $default
	 * @return mixed
	 */
	public static function session($name, $default = null){
		return self::_getValue("Session", $name, $default);
	}

}

?>